<template>
  <div class="components-container">
    <div class="header-form">
      <div class="layui-inline">
        <label class="layui-form-label">业务状态</label>
        <div class="layui-inline">
          <el-radio-group v-model="regValue" @change="getData">
            <el-radio-button :label="unCome" class="radio">未到馆</el-radio-button>
            <el-radio-button :label="all" class="radio">全部</el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">业务编号</label>
        <div class="layui-inline">
          <el-input v-model="selectData.RegbussnumLike" placeholder="请输入业务编号"></el-input>
        </div>
      </div>
      <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
      <el-button @click="btnRepeat">重置</el-button>
    </div>
    <div>
      <ul class="toolList">
        <li><el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button></li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    <mainmodel ref="models" @refreshData="getData"></mainmodel>
  </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>
<script>
import apiBase from "@/api/apiBase.js";
import dataTable from "@/components/Table/DataTable";
import { manage } from "@/mixins/managePage.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import mainmodel from "./numBandMain";
const Modify = "序号绑定";
const Detail = "详情";
export default {
  name: "numBand",
  mixins: [manage],
  data() {
    return {
      selectData: {
        RegdateEquals: null,
        RegcurstatusEquals: 'A'
      },
      regValue: null,
      unCome: "A",
      all: null
    };
  },
  methods: {
      btnShow(btn) {
      switch (btn) {
        case Modify:
          return true;
          break;
        case Detail:
          return this.currentRow != null;
          break;
        default:
      }
    },
    //获取电话预约数据
    getData() {
      this.selectData.RegdateEquals = formatDate(new Date(), "yyyyMMdd");
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: JSON.parse(JSON.stringify(this.selectData))
      };
      console.log(data);
      apiBase.DoService(data, apiBase.getApiAdress().NumBinding.Query, res => {
        this.dataList = res.data.content.OutData;
        this.pageOrder.totalNum = res.data.content.RecordCount;
        this.dataList.forEach(data => {
          data.REGDATE = data.REGDATE.substring(0, 16);
        });
      });
    },
    //获取表头
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetNumBindingColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        case Modify:
          this.$refs.models.open(this.order);
          break;
        case Detail:
          this.$refs.models.open(this.order, this.currentRow);
          break;
        default:
      }
    },
    initSeachdata() {
      this.regValue = this.unCome;
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.selectData.RegcurstatusEquals = "A";
      this.initSeachdata();
      this.getData();
    }
  },
  components: {
    dataTable,
    mainmodel
  },
  created() {
    this.getColumns();
    this.getData();
  },
  mounted() {
    this.initSeachdata();
  },
  watch: {
    regValue: function(val) {
      this.selectData.RegcurstatusEquals = null;
      switch (val) {
        case this.unCome:
          this.selectData.RegcurstatusEquals = "A";
          break;
        case this.all:
          this.selectData.RegcurstatusEquals = null;
          break;
        default:
          break;
      }
    }
  }
};
</script>
